package cn.tedu.weibo.controller;

import cn.tedu.weibo.pojo.dto.WeiboDTO;
import cn.tedu.weibo.pojo.vo.WeiboDetailVO;
import cn.tedu.weibo.pojo.vo.WeiboIndexVO;
import cn.tedu.weibo.response.JsonResult;
import cn.tedu.weibo.service.IWeiboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/weibos")
public class WeiboController {
    @Autowired
    IWeiboService service;
    @PostMapping("add-new")
    public JsonResult addNew(WeiboDTO weiboDTO){
        System.out.println("weiboDTO"+weiboDTO);
        service.addNew(weiboDTO);
        return JsonResult.ok();
    }
    @GetMapping("")
    public JsonResult listForIndex(){
//        调用Service中的获取列表方法,把查询到的weibo数据装进list集合响应给客户端
        List<WeiboIndexVO> list = service.listForIndex();
        return JsonResult.ok(list);
    }
    @GetMapping("{id}")
    public JsonResult weiboById(@PathVariable Long id){
        WeiboDetailVO weiboDetailVO = service.weiboById(id);
        return JsonResult.ok(weiboDetailVO);
    }
}
